package com.rh.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rh.entity.EduCourse;
import com.rh.entity.EduTeacher;
import com.rh.service.EduCourseService;
import com.rh.service.EduTeacherService;
import com.rh.result.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author rh
 * 教师前台管理
 */
@RestController
@RequestMapping("/eduservice/teacherfront")
@Api(tags = "教师前台管理")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    /**
     * 前台教师分页查询
     */
    @ApiOperation(value = "1.教师前端分页")
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public ResultVo getTeacherFrontList(@PathVariable long page,
                                        @PathVariable long limit){
        //mybatisPlus分页
        Page<EduTeacher>pages=new Page<>(page,limit);
        //用一个Map集合封装所有分页数据
        Map<String,Object> map=eduTeacherService.getTeacherList(pages);
        //分页底层要返回分页的所有数据，之前用element-ui里面的分页直接返回total和rows就可以
        return ResultVo.ok().data(map);
    }
    /**
     * 前台教师详情查询
     * 讲师的基本信息和讲师所属的课程
     */
    @ApiOperation(value = "2.教师前端详情")
    @GetMapping("getTeacherFrontInfo/{id}")
    public ResultVo getTeacherFrontInfo(@PathVariable String id){
        //1.根据教师id查询基本信息
        EduTeacher teacher = eduTeacherService.getById(id);
        //2.根据教师id查询课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> eduCourseList = eduCourseService.list(wrapper);
        return ResultVo.ok().data("teacher",teacher).data("courseList",eduCourseList);
    }
}
